package com.cqc.jdk8.Jutil;

import org.junit.Test;

import java.text.DateFormat;
import java.util.Calendar;

/**
 * 就单纯的add操作结果都一样，因为都是将日期+1
 * 不是 月的日期中加1还是年的日期中加1
 */
public class CalendarTest {
    @Test
    public void f1() {
        //今天2025-03-12，值是2025-2-27 11:06:47
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -13);
        System.out.println(DateFormat.getDateInstance().format(calendar.getTime()));
    }
    @Test
    public void f2() {
        //今天2025-03-12，值是2025-2-27
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -13);
        System.out.println(DateFormat.getDateInstance().format(calendar.getTime()));
    }
    @Test
    public void f4() {
        //今天2025-03-12，值是2024-12-30  31+28+12=71
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -72);
        System.out.println(DateFormat.getDateInstance().format(calendar.getTime()));
    }
    @Test
    public void f3() {
        //今天2025-03-12，值是2025-2-27
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, -13);
        System.out.println(DateFormat.getDateInstance().format(calendar.getTime()));
    }
}
